//
//  Notification.swift
//  vr_web
//
//  Created by 李旭峰 on 2020/7/13.
//

import Foundation
protocol NotificationSettable {
    associatedtype defaultKeys: RawRepresentable
}
extension NotificationSettable  where defaultKeys.RawValue == String {
    static func addObserver(observer:Any, sel:Selector,forKey key:defaultKeys, object: Any?){
        NotificationCenter.default.addObserver(observer, selector: sel, name: NSNotification.Name(rawValue: key.rawValue), object: object)
    }
    static func removeObserver(observer:Any,forKey key:defaultKeys, object:Any?){
        NotificationCenter.default.removeObserver(observer, name: NSNotification.Name(rawValue: key.rawValue), object: object)
    }
    static func post(forKey key:defaultKeys,object:Any? = nil,userInfo:[AnyHashable:Any]? = nil){
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: key.rawValue), object: object, userInfo: userInfo)
    }
}
extension NotificationCenter{
    struct Wechat : NotificationSettable {
        enum defaultKeys : String {
            case auth = "com.Asman.App.Key.Notification.Wechat.Auth"
        }
    }
    struct BusinessModule: NotificationSettable {
        enum defaultKeys: String {
            /// 承接页引导
            case myHome_needReloadJournal = "com.Asman.App.Key.UserDefaults.BusinessModule.MyHome.needReloadJournal"
        }
    }
}


extension Notification.Name {
    ///app缓存
    public struct AppChche{
    }
    public struct AppDevices{
        /// 皮肤模式发生改变
        public static let ThemeNeedChange = Notification.Name(rawValue: "com.common.exchange.themeNeedChange")
        /// 语言发生改变
        public static let languageDidChanged = Notification.Name(rawValue: "com.common.app.devices.languagaDidChanged")
    }
    public struct Asman {
        /// 登录状态改变，一般是用户登录完成、退出登录或者token失效
        public static let loginDidChange = Notification.Name(rawValue: "com.common.asman.loginDidChange")
    }
}

